package com.dlut.java5;

import java.math.BigInteger;
import java.util.*;

/**
 * @Author: LiuHeng
 * @Description:
 * @Date: 2022-10-12 14:55
 */
public class T1014_GaoTu_ {


    private static final Map<Character, Character> map = new HashMap<>(){
        {
            put('(',')');
            put('{','}');
            put('[',']');
        }
    };
    /*
    括号表达式
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        if (s.length() >0 && !map.containsKey(s.charAt(0))){
            System.out.println(false);
            return;
        }
        LinkedList<Character> stack = new LinkedList<>();
        stack.addLast('.');
        for(Character c : s.toCharArray()){
            if (map.containsKey(c))
                stack.addLast(c);
            else if (map.get(stack.removeLast()) != c){
                System.out.println(false);
                return;
            }
        }
        System.out.println(stack.size()==1);
    }

    /*
    回文整数
     */
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        String s = in.nextLine();
        int n = s.length();
        for (int i = 0; i < n / 2; i++) {
            if (s.charAt(i) != s.charAt(n - 1 - i)){
                System.out.println(false);
                return;
            }
        }
        System.out.println(true);
    }

    /*
    正则匹配
     */
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        String s1 = in.nextLine();
        String s2 = in.nextLine();
        boolean ans = fun1(s1, s2);
        System.out.println(ans);
    }

    private static boolean fun1(String s, String p) {
        char[] cs = s.toCharArray();
        char[] cp = p.toCharArray();

        boolean[][] dp = new boolean[cs.length+1][cp.length+1];

        dp[0][0] = true;
        for (int i = 1; i <= cp.length; i++) {
            if (cp[i-1] == '*'){
                dp[0][i] = dp[0][i-2];
            }
        }
        for (int i = 1; i <= cs.length; i++) {
            for (int j = 1; j <= cp.length; j++) {
                if (cs[i-1] == cp[j-1] || cp[j-1] == '.'){
                    dp[i][j] = dp[i-1][j-1];
                }else if(cp[j-1] == '*'){
                    if (cs[i-1] == cp[j-2] || cp[j-2] == '.'){
                        dp[i][j] = dp[i][j-2] || dp[i-1][j];
                    }else {
                        dp[i][j] = dp[i][j-2];
                    }
                }
            }
        }
        return dp[cs.length][cp.length];
    }



    public int Decrypt (int encryptedNumber, int decryption, int number) {
        // write code here
        BigInteger temp = new BigInteger(String.valueOf(encryptedNumber));
        BigInteger pow = temp.pow(decryption);
        BigInteger mod = pow.mod(new BigInteger(String.valueOf(number)));

//        for (int i = 0; i < decryption; i++) {
//            temp = (temp * encryptedNumber) % number;
//        }
        return mod.intValue();
    }

    /*
    比较版本
     */
    public int compareVersion (String version1, String version2) {
        // write code here
        String[] s1 = version1.split("\\.");
        String[] s2 = version2.split("\\.");
        int n1 = s1.length;
        int n2 = s2.length;
        int i=0, j=0;
        while (i<n1 && j<n2){
            int temp = s1[i].compareTo(s2[j]);
            if (temp > 0){
                return 1;
            }else if (temp < 0){
                return -1;
            }
            i++;
            j++;
        }
        return 0;
    }
}
